package com.gxa.ssm340.controller;

import com.gxa.ssm340.common.R;
import com.gxa.ssm340.entity.dto.CollectCpnDTO;
import com.gxa.ssm340.entity.pojo.Coupon;
import com.gxa.ssm340.entity.vo.CpnSelectVO;
import com.gxa.ssm340.service.CpnService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * @BelongsProject: huanlianchaoshi
 * @Author: Donglu
 * @CreateTime: 2023-10-23  15:22
 */
@Api(value = "CpnController",tags = "优惠券")
@RequestMapping("/user")
@RestController
public class CpnController {

    @Autowired
    private CpnService cpnService;

    @ApiOperation("优惠券领取界面")
    @PostMapping("/getCpnListForWeb")
   public R selectAllCpn(@RequestParam("phone") String phone) {
        //获取当前时间
        Date date = new Date();

        /*查询还未领取优惠券*/
        List<Coupon> notGetCpn = cpnService.selectNotGetCpn(phone);


        /*查询已领取优惠券*/
        List<Coupon> getCpn = cpnService.selectGetCpn(phone);


        /*领取时间已过期优惠券*/
        List<Coupon> overExpire = cpnService.selectOverExpire(date);


        CpnSelectVO cpnSelectVO = new CpnSelectVO();
        cpnSelectVO.setUserNotGetCpnList(notGetCpn);
        cpnSelectVO.setOverExpire(overExpire);
        cpnSelectVO.setUserGetCpnList(getCpn);


        return R.success(cpnSelectVO);

    }


    @ApiOperation("优惠券领取界面")
    @PostMapping("/getCpn")

    public R collectCpn(@RequestBody CollectCpnDTO collectCpnDTO) {
        cpnService.addGet(collectCpnDTO);
        return R.success();
    }
}

